require 'fileutils'
load 'keys.rb'

OUT_DIR = "out/"
TEMPLATE_DIR = "templates/"

H_FILE = 1
CPP_FILE = 2

def gen_file(key, file)
	class_name = key.capitalize
	table_name = key + "s"

	out_filename = OUT_DIR + class_name
	template_name = TEMPLATE_DIR
	if H_FILE == file
		out_filename += ".h"
		template_name += "h_template"
	else
		out_filename += ".cpp"
		template_name += "cpp_template"
	end

	File.open(template_name, "r") do |template|
		out_file = File.new(out_filename, "w")
		while line = template.gets
			line.gsub!(/\$\(class_name\)/, class_name)
			line.gsub!(/\$\(table_name\)/, table_name)
			out_file.puts(line)
		end
		out_file.close
	end
end

def gen(key)
	gen_file(key, H_FILE)
	gen_file(key, CPP_FILE)
end

KEYS.each do |key|
	gen(key)
end
